package share

import (
	"jslog/service"
	"strings"

	commMail "jslog/common/service"

	"github.com/gin-gonic/gin"
)

type Mail struct {
	service.Comon
}

func (s Mail) Sendmail(c *gin.Context) {

	addressee := c.DefaultPostForm("addressee", "")
	theme := c.DefaultPostForm("theme", "")
	content := c.DefaultPostForm("content", "")

	if addressee == "" {
		s.Error(0, nil, "收件人错误", c)
	}
	if theme == "" {
		s.Error(0, nil, "主题错误", c)
	}
	if content == "" {
		s.Error(0, nil, "内容错误", c)
	}
	addrs := strings.Split(addressee, ",")
	mail := new(commMail.Mail)

	var err error
	if len(addrs) > 1 {
		_, err = mail.GroupSend(addrs, theme, content)
	} else {
		_, err = mail.Send(addressee, theme, content)
	}
	if err == nil {
		s.Succee("发送成功", c)
	}
}
